package com.ss.android.article.browser.view.user;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.browser.R;
import com.ss.android.article.browser.download.DownloadTaskManager;
import com.ss.android.article.browser.download.aa;
import com.ss.android.common.ui.view.ScrollControllableViewPager;
import com.ss.android.common.util.ImmersedStatusBarHelper;
import com.ss.android.common.util.ImmersedStatusBarHelper.ImmersedStatusBarConfig;
import com.ss.android.newmedia.activity.FragmentActivity;

public class UserActionHistoryActivity extends FragmentActivity implements v {
    enum TYPE {
        DOWNLOADING,
        DOWNLOAD,
        BOOK_MARKS,
        HISTORY
    }

    aa a;
    private ScrollControllableViewPager b;
    private int c;
    private int d;
    private Fragment[] e;
    private int f;
    private LinearLayout g;
    private TextView h;
    private TextView i;
    private View j;
    //    private UserActionTabLayout k;
    private TabLayout k;
    private View.OnClickListener l;
    private boolean m;

    public UserActionHistoryActivity() {

        this.e = new Fragment[2];
        this.l = new y(this);
    }

    static int a(UserActionHistoryActivity arg0, int arg1) {
        arg0.f = arg1;
        return arg1;
    }

    private static Fragment a(TYPE arg2) {
        Fragment v0_2;
        switch (ae.a[arg2.ordinal()]) {
            case 2: {
                v0_2 = new e();
                break;
            }
            case 3: {
                v0_2 = new com.ss.android.article.browser.view.user.aaa();
                break;
            }
            case 4: {
                v0_2 = new i();
                break;
            }
            default: {
                v0_2 = new o();
                break;
            }
        }

        return ((Fragment) v0_2);
    }

    static ScrollControllableViewPager a(UserActionHistoryActivity arg1) {
        return arg1.b;
    }

    static boolean a(UserActionHistoryActivity arg0, boolean arg1) {
        arg0.m = arg1;
        return arg1;
    }

    public final void a() {
        this.h.setText(this.getString(com.ss.android.article.browser.R.string.a1r));
    }

    public final void a(boolean arg2) {
        this.i.setEnabled(arg2);
    }

    static void b(UserActionHistoryActivity arg2, int arg3) {
        arg2.d();
        Fragment v0 = arg2.e[arg3];
        if ((v0 instanceof u)) {
            ((u) v0).f();
        }
    }

    static Fragment[] b(UserActionHistoryActivity arg1) {
        return arg1.e;
    }

    public final void b() {
        this.h.setText(this.getString(com.ss.android.article.browser.R.string.uo));
    }

    public final void b(boolean arg2) {
        this.mRightBtn.setEnabled(arg2);
    }

    static int c(UserActionHistoryActivity arg1) {
        return arg1.f;
    }

    public final void c() {
        this.f = 0;
        this.d();
    }

    private void d() {
        int v1 = R.string.br;
        if (this.f == 0) {
            if (this.d == 0) {
                if (this.b.getCurrentItem() == 0) {
                    this.mRightBtn.setText(this.getString(v1));
                } else {
                    this.mRightBtn.setText(this.getString(com.ss.android.article.browser.R.string.bh));
                }

                UIUtils.setVisibility(this.mRightBtn, 0);
            } else {
                if (this.d != 1) {
                } else {
                    this.mRightBtn.setText(this.getString(v1));
                    UIUtils.setVisibility(this.mRightBtn, 0);
                }
            }
            this.b();
            this.b.setScroll(true);
            UIUtils.setVisibility(this.g, 8);
//            this.k.setTabClickable(true);
        } else {
            if (this.f != 1) {
                return;
            }

            this.mRightBtn.setText(this.getString(com.ss.android.article.browser.R.string.iw));
            this.b.setScroll(false);
            UIUtils.setVisibility(this.mRightBtn, 0);
            UIUtils.setVisibility(this.g, 0);
//            this.k.setTabClickable(false);
        }
    }

    static int d(UserActionHistoryActivity arg1) {
        return arg1.d;
    }

    static TextView e(UserActionHistoryActivity arg1) {
        return arg1.mRightBtn;
    }

    static void f(UserActionHistoryActivity arg0) {
        arg0.d();
    }

    static boolean g(UserActionHistoryActivity arg2) {
        return TextUtils.equals(arg2.h.getText(), arg2.getString(com.ss.android.article.browser.R.string.uo));
    }

    public ImmersedStatusBarConfig getImmersedStatusBarConfig() {
        ImmersedStatusBarConfig v0 = new ImmersedStatusBarConfig();
        v0.mFitsSystemWindows = false;
        v0.mIsAutoSwitchStatusBarStyle = true;
        v0.mIsUseLightStatusBar = true;
        v0.setStatusBarColor(com.ss.android.article.browser.R.color.white);
        return v0;
    }

    public int getLayout() {
        return R.layout.a9;
    }

    static void h(UserActionHistoryActivity arg0) {
        arg0.onBackBtnClick();
    }

    public void init() {
        super.init();
        this.b = (ScrollControllableViewPager) this.findViewById(R.id.view_pager);
        this.k = (TabLayout) this.findViewById(R.id.i9);
        this.j = this.findViewById(com.ss.android.article.browser.R.id.i8);
//        this.k.setLineWidth(((int) com.bytedance.common.utility.g.b(((Context) this), 14f)));
        this.g = (LinearLayout) this.findViewById(R.id.ia);
        this.h = (TextView) this.findViewById(R.id.ib);
        this.i = (TextView) this.findViewById(R.id.delete);
        this.i.setOnClickListener(new z(this));
        Intent v0 = this.getIntent();
        if (v0 == null) {
            this.finish();
        } else {
            this.c = v0.getIntExtra("default_select_page", 0);
            this.d = v0.getIntExtra("show_content", 0);
            if (this.d > 0) {
                this.e[0] = UserActionHistoryActivity.a(TYPE.DOWNLOADING);
                this.e[1] = UserActionHistoryActivity.a(TYPE.DOWNLOAD);
                this.a = new com.ss.android.article.browser.download.aa();
            } else {
                this.e[0] = UserActionHistoryActivity.a(TYPE.BOOK_MARKS);
                this.e[1] = UserActionHistoryActivity.a(TYPE.HISTORY);
            }

            this.b.setAdapter(new UserActionHistoryPagerAdapter(this, this.getSupportFragmentManager()));
            this.b.addOnPageChangeListener(new ab(this));
            this.k.setupWithViewPager(this.b);
            this.f = 0;
            this.d();
            this.mRightBtn.setOnClickListener(this.l);
            this.h.setOnClickListener(new ac(this));
            this.j.setOnClickListener(new ad(this));
            this.b.setCurrentItem(this.c);
            boolean v0_1 = this.b.getCurrentItem() <= 0 ? true : false;
            this.m = v0_1;
            ImmersedStatusBarHelper.setUseLightStatusBar(this.getWindow(), true);
        }
    }

    public void onDestroy() {
        super.onDestroy();
        if (this.a != null) {
            DownloadTaskManager.getInstance().e = null;
        }
    }

    public boolean onKeyDown(int arg5, KeyEvent arg6) {
        boolean v0_1;
        if (arg5 != 4 || this.f != 1) {
            v0_1 = super.onKeyDown(arg5, arg6);
        } else {
            this.f = 0;
            int v0 = this.b.getCurrentItem();
            if ((this.e[v0] instanceof t)) {
                ((t) this.e[v0]).a(false);
            }

            this.d();
            v0_1 = true;
        }

        return v0_1;
    }

    public boolean useSwipeRight() {
        return this.m;
    }

    public boolean userSwipeLeft() {
        return false;
    }
}

